package exercise;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;

/*
d.获得一个日期所在的周的星期几的日期，
如要找出2023年2月3日所在周的星期一是几号
 */
public class ex4 {
    public static void main(String[] args) {
        while (true) {
//            test1();
            test2();
        }

    }

    private static void test2() {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入日期(yyyy-MM-dd)：");
        LocalDate localDate = LocalDate.parse(sc.next());
        System.out.println("请输入星期：");
        int day = sc.nextInt();

        LocalDate monday = localDate.with(DayOfWeek.MONDAY);//设置星期一


        System.out.println("dayOfMonth = " + monday);
    }

    private static void test1() {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入日期(yyyy-MM-dd)：");
        LocalDate localDate = LocalDate.parse(sc.next());
        System.out.println("请输入星期：");
        int day = sc.nextInt();

        DayOfWeek dayOfWeek = localDate.getDayOfWeek();//获取输入日期的星期
        int i = day - dayOfWeek.getValue();//输入星期与输入日期的星期差值

        localDate = localDate.plusDays(i);
        int dayOfMonth = localDate.getDayOfMonth();
        System.out.println("dayOfMonth = " + dayOfMonth);
    }
}
